import request from '@/utils/axios'

export interface ProfileType {
  id: number
  username: string
  nickname: string
  dept: {
    id: number
    name: string
  }
  roles: {
    id: number
    name: string
  }[]
  posts: {
    id: number
    name: string
  }[]
  socialUsers: {
    type: number
    openid: string
  }[]
  email: string
  mobile: string
  sex: number
  avatar: string
  status: number
  remark: string
  loginIp: string
  loginDate: Date
  create_time: Date
}

export interface UserProfileUpdateReqType {
  nickname: string
  email: string
  mobile: string
  sex: number
}

/**
 * 用户接口
 */
export const ProfileApi = {
  // 查询用户个人信息
  detail: () => {
    return request.get({ url: '/system/user/profile/detail', is_mock: true })
  },
  // 修改用户个人信息
  update: (data: UserProfileUpdateReqType) => {
    return request.put({ url: '/system/user/profile/update', data, is_mock: true })
  },
  // 用户密码重置
  updatePassword: (oldPassword: string, newPassword: string) => {
    return request.put({
      url: '/system/user/profile/update-password',
      data: {
        oldPassword: oldPassword,
        newPassword: newPassword
      },
      is_mock: true
    })
  },
  // 用户头像上传
  uploadAvatar: (id: number, avatar: string) => {
    return request.post({ url: '/system/user/profile/update-avatar', data: { id, avatar }, is_mock: true })
  }
}
